import path from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ElementPlus from 'unplugin-element-plus/vite'

// https://vitejs.dev/config/
export default defineConfig({
  define: ['MODE', 'APIBASE', 'APP_NAME'].reduce((t, k) => {
    return { ...t, [`process.env.${k}`]: JSON.stringify(process.env[k]) }
  }, {}),
  resolve: {
    alias: {
      '~/': `${path.resolve(__dirname, 'packages/app')}/`
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "~/assets/theme/default.scss" as *;`
      }
    }
  },
  plugins: [
    vue(),
    ElementPlus({ useSource: true })
  ],
  server: {
    proxy: {
      '/api': {
        target: 'https://miniprogram.sindvision.com',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api/, '')
      }
    }
  }
})
